﻿// =================================================================== 
// 数据访问层(GDIT.DAL)
//====================================================================
// 文件：DPicInfo.cs
// 项目名称：学院网站
// 创建时间：2012-08-08
// 负责人：ChenZhiGang
//引用DevExpress.Data.Filtering，DevExpress.Xpo程序集
// 程序集介绍：图片信息数据访问层
// ===================================================================
using GDIT.Model;
using DevExpress.Data.Filtering;
using DevExpress.Xpo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GDIT.Pattern;

namespace GDIT.DAL
{
    public class DPicInfo : IPicInfo
    {

        private XpoHelper.Test<Mtb_PicInfo> userOperation = null;

        /// <summary>
        /// 新增图片信息
        /// </summary>
        /// <param name="detailMenu">需要新增的图片信息对象</param>
        /// <returns>1：新增成功 2：新增失败</returns>
        public int InsertPicInfo(Mtb_PicInfo picInfo)
        {
            return XpoHelper.SaveAdded(picInfo);
        }

        /// <summary>
        /// 删除图片信息
        /// </summary>
        /// <param name="detailMenu">需要删除的图片信息对象</param>
        /// <returns>1：删除成功 0：删除失败</returns>
        public int DeletePicInfo(Mtb_PicInfo picInfo)
        {
            userOperation = new XpoHelper.Test<Mtb_PicInfo>();
            return userOperation.Delete(picInfo.OID);
        }

        /// <summary>
        /// 更新图片信息
        /// </summary>
        /// <param name="detailMenu">需要更新的图片信息对象</param>
        /// <returns>1：更新成功 0：更新失败</returns>
        public int UpdatePicInfo(Mtb_PicInfo picInfo)
        {
            userOperation = new XpoHelper.Test<Mtb_PicInfo>();
            XPCollection xp = userOperation.Operation("OID", picInfo.OID);
            foreach (Mtb_PicInfo b in xp)
            {
                b.PicPath = picInfo.PicPath;
                b.LinkAddress = picInfo.LinkAddress;
                b.Visible = picInfo.Visible;
                b.Alt = picInfo.Alt;
                return XpoHelper.SaveModified(b);
            }
            return 0;
        }

        /// <summary>
        /// 查询所有的图片信息列表
        /// </summary>
        /// <param name="picTypeName">要查询的图片类型名称</param>
        /// <returns>所有的图片信息列表</returns>
        public XPCollection SelectPicInfo(string picTypeName)
        {
            int i = 0;
            XPCollection xp = new XPCollection(typeof(Mtb_PicType), new BinaryOperator("TypeName",picTypeName,BinaryOperatorType.Equal));
            foreach (Mtb_PicType type in xp)
            {
                i = type.OID;
            }
            XPCollection infos = new XPCollection(typeof(Mtb_PicInfo), new BinaryOperator("PicType",i,BinaryOperatorType.Equal));
            return infos;
        }

        /// <summary>
        /// 查询单一的图片信息对象
        /// </summary>
        /// <returns>单一的图片信息对象</returns>
        public Mtb_PicInfo SelectPicInfoByPic(Mtb_PicInfo picInfo)
        {
            Mtb_PicInfo bulletin = null;
            userOperation = new XpoHelper.Test<Mtb_PicInfo>();
            XPCollection xp = userOperation.Operation("OID", picInfo.OID);
            foreach (Mtb_PicInfo b in xp)
            {
                bulletin = b;
            }
            return bulletin;
        }
    }
}
